package com.huawei.mptcp.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

/**
 * export test data to csv , then could analysis by manual
 * @author hujiangshui
 *
 */
public class ExportDataCsvUtil {
	private static final String TAG = "ExportDataCsvUtil";

	/**
	 * test data will append to csv file 
	 */
	public static void exportDataCsvWithAppend(String csvFilePath,String csvFileName,ArrayList<Double> dataCollected) {
		BufferedWriter bfWriter = null;
		try {
			bfWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(csvFilePath,csvFileName),true)));
			for(Double temData: dataCollected) {
				bfWriter.append(temData.toString()).append(",");
			}
			bfWriter.append("\r\n");
			bfWriter.flush();
			dataCollected.clear();
		}catch(Exception e) {
			ILogUtil.exception(csvFileName, e);
		}finally{
			if(bfWriter != null) {
				try {
					bfWriter.close();
				} catch (IOException e) {
					ILogUtil.exception(csvFileName, e);
				}
			}
		}
		
		
	}
	
}
